using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Coriander.Google.Charting
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>
    /// lg,<angle>,<color 1>,<offset 1>,<color n>,<offset n>
    /// </remarks>
    public class ChartGradientFill : ChartFill
    {
        #region * Fields, properties and ctors * 

        Double angle, startOffset, endOffset;

        Color startColor, endColor;

        /// <summary>
        /// 
        /// </summary>
        public Color EndColor
        {
            get { return endColor; }
            set { endColor = value; }
        }

        /// <summary>
        /// Gets or sets at what point the color is pure where: 0 specifies the 
        /// right-most chart position and 1 the left-most.
        /// </summary>
        public Double StartOffset
        {
            get { return startOffset; }
            set { startOffset = value; }
        }

        /// <summary>
        /// Gets or sets at what point the color is pure where: 0 specifies the 
        /// right-most chart position and 1 the left-most.
        /// </summary>
        public Double EndOffset
        {
            get { return endOffset; }
            set { endOffset = value; }
        }

        /// <summary>
        /// Gets or sets the angle of the gradient between 
        /// 0 (horizontal) and 90 (vertical).
        /// </summary>
        public Double Angle
        {
            get { return angle; }
            set { angle = value; }
        }

        /// <summary>
        /// Gets or sets the RRGGBB format hexadecimal color value for the gradient.
        /// </summary>
        public Color StartColor
        {
            get { return startColor; }
            set { startColor = value; }
        }

        /// <summary>
        /// ctor
        /// </summary>
        public ChartGradientFill() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="chartFillType"></param>
        /// <param name="angle"></param>
        /// <param name="startColor"></param>
        /// <param name="startOffset"></param>
        /// <param name="endColor"></param>
        /// <param name="endOffset"></param>
        public ChartGradientFill(
            ChartFillType chartFillType,
            Double angle,
            Color startColor,
            Double startOffset,
            Color endColor,
            Double endOffset
        )
        {
            ChartFillType       = chartFillType;
            this.angle          = angle;
            this.startColor     = startColor;
            this.startOffset    = startOffset;
            this.endColor       = endColor;
            this.endOffset      = endOffset; 
        }

        #endregion
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="angle"></param>
        /// <returns></returns>
        public static  Boolean IsValidAngle (Double angle) 
        {
            return 0 <= angle && angle <= 90;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException" />
        protected override string GetValue()
        {
            if (false == IsValidAngle(Angle))
                throw new InvalidOperationException(
                    "Invalid angle. Value must be betwen zero and 90."
            );
 
            return String.Format(
                "{0},{1},{2},{3},{4},{5},{6}", // Only support single color
                ChartFillType,
                "lg",
                Angle, 
                ChartColor.ToHtml(StartColor, true),
                StartOffset, 
                ChartColor.ToHtml(EndColor, true),
                EndOffset
            );   
        }
    }
}
